package cn.wyd.shield.http.filter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UrlFilter {
    private ConcurrentHashMap<String,Boolean> urls;
    private Pattern pattern;

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = Pattern.compile(pattern);
    }

    public Map<String, Boolean> getUrls() {
        return urls;
    }

    public void setUrls(ConcurrentHashMap<String, Boolean> urls) {
        this.urls = urls;
    }

    public Boolean getUrls(String key) {
        Boolean flag = urls.get(key);
        if(flag==null){
            Matcher matcher = pattern.matcher(key);
            flag = matcher.matches();
            urls.put(key,flag);
            return flag ;
        }else{
            return flag ;
        }
    }
}
